import ls from 'store2'
export const checkTerminal = () => {
  var u = navigator.userAgent
  var chrome = u.match(/Chrome\/([\d.]+)/) || u.match(/CriOS\/([\d.]+)/)
  var isWechat = u.toLowerCase().match(/MicroMessenger/i) == 'micromessenger' || u.match(/_SQ_/i) == '_sq_'
  var isAndroid = u.match(/(Android);?[\s\/]+([\d.]+)?/)
  var isiOS = !chrome && u.match(/(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/)
  if (isWechat) {
    return 'wechat'
  } else if (isiOS) {
    return 'ios'
  } else if (isAndroid) {
    return 'android'
  }
}
export const backAppOrWx = () => {
  if (checkTerminal() === "ios") {
    window.webkit.messageHandlers.backMessage.postMessage("back");
  } else if (checkTerminal() === "android") {
    ZMParentsJsToAndroid.backMessage("back");
  } else {
    window.$nuxt.$router.back()
    // if (ls.get("userData").userType === 3) {
    //   let url = process.env.workUrl + "/wx-yxk/#/teachers/teaindex";
    //   window.location.replace(url);
    // } else {
    //   let url = process.env.workUrl + "/wx-yxk/#/user";
    //   window.location.replace(url);
    // }
  }
}
